package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.domain.Business;
import org.example.dto.GoodsDto;
import org.example.dto.StockLogDto;
import org.example.service.*;
import org.example.vo.GoodsDepositVo;
import org.example.vo.WarehouseVo;
import org.example.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RequestMapping("stock")
@RestController
@Slf4j
public class StockController {

    @Autowired
    private WarehouseService warehouseService;
    @Autowired
    private GoodsDepositService goodsDepositService;
    @Autowired
    private UserRoleService userRoleService;
    @Autowired
    private BusinessService businessService;
    @Autowired
    private StockLogService stockLogService;
    @Autowired
    private HttpServletResponse response;
    /**
     * 展示仓库列表
     *
     * @param warehouseVo
     * @return
     */
    @RequestMapping("list")
    public Result list(WarehouseVo warehouseVo) {
        List<WarehouseVo> warehouseList = warehouseService.listAll(warehouseVo);
        return Result.success(warehouseList);
    }

    /**
     * 仓库随机盘点
     *
     * @param stockLogDto
     * @return
     */
    @RequestMapping("stockLog")
    public Result stockLog(StockLogDto stockLogDto) {
        stockLogService.stockLog(stockLogDto);
        return Result.success();
    }

    @RequestMapping("/exportExcel/{warehouseName}")
    public void exportExcel(@PathVariable("warehouseName") String warehouseName){
        stockLogService.exportExcel(response,warehouseName);
    }


    /**
     * 展示仓库的每条数据
     *
     * @param id
     * @return
     */
    @RequestMapping("/getById/{id}")
    public Result getById(@PathVariable("id") Integer id) {
        List<GoodsDepositVo> goodsDepositVo = goodsDepositService.getById(id);
        return Result.success(goodsDepositVo);
    }

    /**
     * 出库
     *
     * @return
     */
    @RequestMapping("outStock")
    public Result outStock(@RequestBody GoodsDto goodsDto) {
        log.info("参数:{}", goodsDto.getList());
        goodsDepositService.delGoods(goodsDto);
        return Result.success(goodsDto);
    }


    /**
     * 查询司机
     */
    @RequestMapping("driverList")
    public Result driverList() {
        return userRoleService.driverList();
    }


    /**
     * 查询生产厂商
     *
     * @return
     */
    @RequestMapping("businessList")
    public Result businessList() {
        List<Business> businessList = businessService.listAll();
        return Result.success(businessList);
    }
}
